package v2;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * 负责把复杂问分成若干个问题
 * mapreduce
 * Created by chuan on 2019-4-18.
 */
public class MaxTemperatureMapper extends Mapper<LongWritable, Text, Text, IntWritable>{

    private NcdcRecordParser parser = new NcdcRecordParser();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//        String line = value.toString();
//        String year = line.substring(15, 19);
//        int airTemperature = Integer.parseInt(line.substring(87, 92));
//        context.write(new Text(year), new IntWritable(airTemperature));
        parser.parse(value); //传入需要解析的
        if(parser.isValidTemperature()) {
            context.write(new Text(parser.getYear()), new IntWritable(parser.getAirTemperature()));
        }
    }
}